﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MegavaniaX;

namespace MegavaniaX
{
    /// <summary>
    /// Animation manager.  Manages a dictionary of all animations, and will produce animations on demand for client objects.
    /// </summary>
    public static class AnimationManager
    {
        /// <summary>
        /// The dictionary of animations.
        /// </summary>
        private static Dictionary<String, Animation> animationDictionary = new Dictionary<String, Animation>();

        public static void RegisterAnimation(string name, Animation anim)
        {
            if (animationDictionary.ContainsKey(name))
            {
                throw new MegavaniaException("Cannot add animation with duplicate name.");
            }
            animationDictionary.Add(name, anim);
        }

        /// <summary>
        /// Makes an animation from the dictionary of animations.
        /// </summary>
        /// <param name="name">Name of the animation to look for in the dictionary.</param>
        /// <returns>A new animation.</returns>
        /// <exception cref="MegavaniaException">Thrown when the animation name could not be found.</exception>
        public static Animation MakeAnimation(String name)
        {
            if (!animationDictionary.ContainsKey(name))
            {
                throw new MegavaniaException("Could not find animation with name " + name);
            }
            return (Animation)animationDictionary[name].Clone();
        }

    }
}
